package com.lhh.myspringboot.collection.set;

import java.util.Comparator;
import java.util.TreeMap;

public class PersonTest {
    private Integer age;

    public PersonTest(Integer age) {
        this.age = age;
    }

    public Integer getAge() {
        return age;
    }


    public static void main(String[] args) {
        TreeMap<PersonTest, String> treeMap = new TreeMap<>(new Comparator<PersonTest>() {
            @Override
            public int compare(PersonTest personTest1, PersonTest personTest2) {
                int num = personTest1.getAge() - personTest2.getAge();
                return Integer.compare(num, 0);
            }
        });
        treeMap.put(new PersonTest(3), "person1");
        treeMap.put(new PersonTest(18), "person2");
        treeMap.put(new PersonTest(35), "person3");
        treeMap.put(new PersonTest(16), "person4");
        treeMap.entrySet().stream().forEach(personStringEntry -> {
            System.out.println(personStringEntry.getValue());
        });
    }


}
